package com.cong.websocketdemo.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author cong
 * @since 2022/1/7 18:31
 */
public class Result {
    final static LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();

    /**
     * 存在下一条记录
     * @param message
     */
    public static void add(String message) {

        queue.offer(message);
    }

    /**
     * 获取结果
     * @param timeout
     * @param unit
     * @return
     */
    public static String  get(Long timeout, TimeUnit unit) {

        try {
            return queue.poll(timeout, unit);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }
}
